{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            A           B           C           D           E           F  \\\n",
      "1   64.230535  414.251229  590.797457  755.782414  457.775154  341.377150   \n",
      "2    9.420680   84.462616  663.722396  751.228024  517.420684  401.280969   \n",
      "3  144.893145  945.168210  461.802970  812.206816  894.372552   99.195496   \n",
      "4  629.672527  733.251079  628.256490  475.254454  373.103932   42.316176   \n",
      "5  884.805920  553.647713  788.517807  684.622371  457.559357  529.670852   \n",
      "6  638.643259  342.204751  607.200646  579.805959  960.988170  778.269347   \n",
      "\n",
      "            G           H           I           J           K  \n",
      "1  727.256058  856.117878  832.046331  437.883807  792.355928  \n",
      "2  530.679766  835.332842  132.180166  969.541521  632.416024  \n",
      "3  416.863669  848.370111  554.049803  106.297028  803.602419  \n",
      "4  743.434947  956.511834  386.551145  448.563744  171.205639  \n",
      "5  751.827677   29.373344  197.761702  144.432629  330.381917  \n",
      "6  364.818106  774.142853  360.058750  427.513780  262.943764  \n"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "    \"A\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"B\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"C\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"D\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"E\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"F\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"G\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"H\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"I\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"J\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\")),\n",
    "    \"K\":pd.Series(np.random.rand(6)*1000,index=list(\"123456\"))\n",
    "})\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           A          B         C         D         E          F         G  \\\n",
      "1        NaN        NaN       NaN       NaN       NaN        NaN       NaN   \n",
      "2  -0.853330  -0.796108  0.123435 -0.006026  0.130294   0.175477 -0.270299   \n",
      "3  14.380328  10.190373 -0.304223  0.081172  0.728521  -0.752803 -0.214472   \n",
      "4   3.345772  -0.224211  0.360443 -0.414860 -0.582832  -0.573406  0.783401   \n",
      "5   0.405184  -0.244941  0.255089  0.440539  0.226359  11.516983  0.011289   \n",
      "6  -0.278211  -0.381909 -0.229947 -0.153101  1.100248   0.469345 -0.514758   \n",
      "\n",
      "           H         I         J         K  \n",
      "1        NaN       NaN       NaN       NaN  \n",
      "2  -0.024278 -0.841138  1.214152 -0.201854  \n",
      "3   0.015607  3.191626 -0.890364  0.270686  \n",
      "4   0.127470 -0.302317  3.219909 -0.786952  \n",
      "5  -0.969291 -0.488394 -0.678011  0.929737  \n",
      "6  25.355285  0.820670  1.959953 -0.204122  \n"
     ]
    }
   ],
   "source": [
    "# 百分比变化 pct_change() （第n与第n+1比率）\n",
    "print(df.pct_change())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.6302752807842114\n"
     ]
    }
   ],
   "source": [
    "# 协方差 cor()\n",
    "s1 = pd.Series(np.random.randn(10))\n",
    "s2 = pd.Series(np.random.randn(10))\n",
    "print (s1.cov(s2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4286141662873224\n"
     ]
    }
   ],
   "source": [
    "# 相关系数 corr()\n",
    "print(s1.corr(s2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0     3.0\n",
      "1     8.0\n",
      "2     7.0\n",
      "3     5.0\n",
      "4     1.0\n",
      "5     9.0\n",
      "6    10.0\n",
      "7     2.0\n",
      "8     6.0\n",
      "9     4.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 排名 rank()\n",
    "print(s1.rank())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
